home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
151-175
/
169
/
src
/
shell
/
hat.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-13
|
992b
|
45 lines
/*
* HAT.C
*
* Modify the last history entry ^search^replace. Called from
* MAIN.C
*
*/
extern char *last_history_entry();
hat_replace(buf)
char *buf;
{
char res[256];
char *ptr, *hb, *repstr, *srchstr;
int searchlen, replacelen;
srchstr = buf + 1;
for (repstr = srchstr; *repstr && *repstr != '^'; ++repstr);
if (*repstr) {
searchlen = repstr - srchstr;
*repstr = '\0';
++repstr;
}
replacelen = strlen(repstr);
for (ptr = hb = last_history_entry(); *ptr; ++ptr) {
if (strncmp(ptr, srchstr, searchlen) == 0) {
bmov(hb, res, ptr - hb); /* first part of history */
res[ptr-hb] = '\0'; /* add 0 */
strcat(res, repstr); /* add replace string */
strcat(res, ptr+searchlen); /* add rest of history */
strcpy(buf, res); /* copy */
puts (buf);
return(1); /* done */
}
}
puts ("modifier failed");
*buf = '\0';
return(0);
}